#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# vim: set et sw=4 ts=4 sts=4 ff=unix fenc=utf8:
# Author: xiyoulaoyuanjia
#         xiyoulaoyuanjia@gmail.com

from tornado.ioloop import IOLoop
from tornado.httpserver import HTTPServer
import tornado.log
import logging
import sys

from app import Application

def run(host=None, port=None, debug=None, message_queue=None, **option):
    '''
    '''
    ##init logger
    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG if debug else logging.INFO)
    channel = logging.StreamHandler(sys.stdout)
    channel.setFormatter(tornado.log.LogFormatter())
    logger.addHandler(channel)

    http_server = HTTPServer(Application(message_queue), xheaders=True)
    http_server.bind(port, host)
    http_server.start()
    logging.info("http server started on %s:%s", host, port)
    
    IOLoop.instance().start()
    



if __name__ == '__main__':
    run()

